package com.winsomely.leecode;

/**
 * 字符串中的第一个唯一字符
 * 
 * @author liujiawei
 *
 */
public class FirstUniqChar {

	public int firstUniqChar(String s) {
		if (s.length() == 1) {
			return 0;
		}
		int[] in = new int[26];

		for (int i = 0; i < s.length(); i++) {
			in[s.charAt(i) - 'a']++;
		}
		for (int i = 0; i < s.length(); i++) {
			if (in[s.charAt(i) - 'a'] == 1) {
				return i;
			}
		}
		return -1;
	}

	public static void main(String[] args) {
		FirstUniqChar t = new FirstUniqChar();
		String s = "dogd";
		System.out.println(t.firstUniqChar(s));
	}

}
